import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    // 从本地存储中获取，如果没有则为未登录null
    user: JSON.parse(window.localStorage.getItem('user')) || null
  },
  mutations: {
    setUser (state, payload) {
      state.user = JSON.parse(payload)
      // 保存到本地
      window.localStorage.setItem('user', payload)
    }
  }
})

export default store
